package com.share.device.api;

import com.share.common.core.constant.DeviceConstants;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.security.annotation.RequiresLogin;
import com.share.device.service.IDeviceService;
import com.share.device.service.IStationService;
import com.share.device.vo.StationVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 设备管理微信小程序端接口管理
 * @author zxl
 * @date 2025年03月26日 17:10
 */
@Tag(name = "设备管理微信小程序端接口管理")
@RequestMapping("/device")
@RestController
public class DeviceApiController {

    @Resource
    IDeviceService deviceService;

    @Resource
    IStationService stationService;

    @Operation(summary = "根据经纬度搜索附近门店（站点）")
    @RequiresLogin
    @GetMapping("/nearbyStation/{latitude}/{longitude}")
    public AjaxResult nearbyStation(@PathVariable String latitude, @PathVariable String longitude) {
        // 附近站点信息列表
        List<StationVo> stationVoList = deviceService.nearbyStation(latitude, longitude, DeviceConstants.SEARCH_H5_RADIUS);
        if (CollectionUtils.isEmpty(stationVoList)) {
            stationService.updateData();
        }
        return AjaxResult.success(stationVoList);
    }

    @Operation(summary = "根据id获取门店详情")
    @RequiresLogin
    @GetMapping("/getStation/{id}/{latitude}/{longitude}")
    public AjaxResult getStation(
            @PathVariable Long id,
            @PathVariable String latitude,
            @PathVariable String longitude
                                 ) {
        return AjaxResult.success(deviceService.getStation(id, longitude, latitude));
    }
}
